package com.tanger.im.service.user;

import com.tanger.common.exception.AbstractController;
import com.tanger.common.result.ActionResult;
import com.tanger.common.utils.StringUtil;
import com.tanger.im.entity.IMUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @Description IM用户控制层
 * @Author Hchenbin
 * @Date 2023/12/25 9:19
 * @Version 1.0
 */
@RestController
@RequestMapping("/tanger/api/im/user")
@Api(value = "IM:IM用户",tags="IM:IM用户")
public class IMUserController extends AbstractController{

    @Autowired
    private IMUserService service;

    @ApiImplicitParam(name = "id", value = "IM用户ID", required = true, paramType = "query" ,dataType = "Long")
    @ApiOperation(value = "按IM用户ID获取用户详情")
    @GetMapping("/findOneById")
    public ActionResult<IMUserVO> findOneById(@RequestParam Long id){
        if (StringUtil.isNull(id)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return ActionResult.buildResultSuccess(service.findOneById(id));
    }

    @ApiImplicitParam(name = "userId", value = "系统用户ID", required = true, paramType = "query" ,dataType = "Long")
    @ApiOperation(value = "按系统用户ID获取用户详情")
    @GetMapping("/findOne")
    public ActionResult<IMUserVO> findOne(@RequestParam Long userId){
        if (StringUtil.isNull(userId)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return ActionResult.buildResultSuccess(service.findOne(userId));
    }

    @ApiOperation(value = "保存IM用户信息")
    @PostMapping("/save")
    public ActionResult save(@RequestBody IMUserVO vo) {
        if (Objects.isNull(vo)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return service.save(vo);
    }

    @ApiImplicitParam(name = "id", value = "IM用户ID", required = true, paramType = "query" ,dataType = "Long")
    @ApiOperation(value = "注销IM用户")
    @PostMapping("/cancel")
    public ActionResult cancel(@RequestParam Long id) {
        if (StringUtil.isNull(id)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return service.cancel(id);
    }
}

